package advanced.network;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 简单爬虫的原理
 * 从指定url连接中,  爬取数据
 */
public class L_Ratile {
    public static void main(String[] args) throws IOException {
        //获取URL
        URL url = new URL("https://www.dianping.com");
        //downloda resources
//        InputStream is = url.openStream();//如果没有权限汇报 403 异常
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        //模拟使用浏览器访问该url,欺骗服务器,略过权限控制
        conn.setRequestMethod("GET");
        conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.90 Safari/537.36");
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
        String msg = null;
        while (null != (msg = br.readLine())) {
            System.out.println(msg);
        }
        br.close();
        //分析


    }
}
